//==================== 数据标签所需函数=========================
import pageofficeCtrlUtil from "@/plugins/pageoffice/pageoffice-word-excel.js";

let isFromStart = false, lastOpTag = '', findCount = 0

export const dataTagUtil = {
    locateDataTag: (tagName) => {
        pageofficectrl.word.SelectionCollapse(0)
        if (isFromStart) {
            if (lastOpTag === tagName) {
                pageofficectrl.word.HomeKey(6)
            }
            isFromStart = false
        }
        if (pageofficectrl.word.FindNextText(tagName)) {
            findCount ++
        } else {
            let msg = findCount === 0 ? '未搜索到当前数据标签' : `已经搜索到文档末尾，共 ${findCount} 处`
            pageofficeCtrlUtil.msgInfo(msg)
            isFromStart = true
            findCount = 0
        }
        lastOpTag = tagName
    },
    addDataTag: (tagName) => {
        pageofficectrl.word.SetTextToSelection(tagName)
    },
    deleteDataTag: (tagName) => {
        let selectText = pageofficectrl.word.GetTextFromSelection()
        if (tagName !== selectText) {
            pageofficeCtrlUtil.msgInfo('请先执行 ‘' + tagName + '’ 的定位操作，然后再删除。')
        } else {
            pageofficectrl.word.SetTextToSelection('')
        }
    }
}
